package com.example.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author YAO
 * @create 2021-04-19 19:51
 */
public class Servlet1 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求参数
        String username = req.getParameter("username");

        System.out.println("在Servlet1中查看参数" + username);

        // 传递到Servlet2
        req.setAttribute("key","柜台1的章");

        //Servlet2怎么走
        //请求转发必须以/打头，斜杠地址为http://ip:port/工程名/  映射到web目录
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/servlet2");
        //传递给Servlet2
        requestDispatcher.forward(req,resp);
    }
}
